//
//  UserApi.m
//  EFExtend
//
//  Created by mac on 15/3/27.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "UserApi.h"
#import "UserBean.h"



@implementation UserApi

- (UserBean *)getUserBean{
    UserBean *bean = [UserBean defaultBean];
    return bean;
}

- (void)login:(NSString*)command Username:(NSString *)userN password:(NSString *)pwd{
    
    NSString *date = [[NSDate date] stringWithDateFormat:nil forTimezone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    NSString *psw = [[pwd MD5String] lowercaseString];
    NSString *passw=[NSString stringWithFormat:@"%@%@",date,psw];
    passw = [[passw MD5String] lowercaseString];
    
    NSDictionary *dic = @{@"LoginName":userN,
                          @"key":passw,
                          @"dateTime":date,
                          @"appName":@"woyunhang",
                          };
    
    [self registerClassName:[NSNull class] forCommand:command];
    
    [[[[self webApiWithCommand:@"/user/Login" timeout:20.f]
       setWebName:command]
      setWebParams:dic]
     send];
    
}

ON_WebAPI(dlg){
    if (dlg.sending) {
        
        [self callbackListenter:dlg.name bean:nil state:APIProcessLoading error:nil];
        
    }else if (dlg.progressed){
        // 必须在发送web Api 时指定 setWebProcess:YES
        //          dlg.ownRequest.downloadPercent;
        //          dlg.ownRequest.uploadPercent;
        [self callbackListenter:dlg.name bean:nil state:APIProcessDataAppending error:nil];
        
    }else if (dlg.succeed){
        NSDictionary *dic = [dlg.output objectForKey:[HMWebAPI params]];
//        [dic pritfMemberForClassName:@"LoginBean" coding:NO numberAnalysis:NO];
        
        if ([dlg isName:@"Login"]) {
            
        }
        [self callbackListenter:dlg.name bean:nil state:APIProcessSucced error:nil];
        
    }else{
        APIProcess state = APIProcessFailed;
        if (dlg.timeout) {
            state = APIProcessTimeOut;
        }
        [self callbackListenter:dlg.name bean:nil state:state error:nil];
    }
}


@end
